package com.yyaccp.appinfo.utils;

import redis.clients.jedis.Jedis;

public class JedisUtils {

    private static final String HOST = "127.0.0.1";

    public static void set(String key,String value){
        Jedis jedis = new Jedis(HOST);
        try{
            jedis.set(key,value);
        }catch(Exception e){
            e.printStackTrace();
        }finally {
            jedis.close();
        }
    }

    public static void setex(String key,int seconds,String value){
        Jedis jedis = new Jedis(HOST);
        try{
            jedis.setex(key,seconds,value);
        }catch(Exception e){
            e.printStackTrace();
        }finally {
            jedis.close();
        }
    }

    public static Long ttl(String key){
        Jedis jedis = new Jedis(HOST);
        try{
            return jedis.ttl(key);
        }catch(Exception e){
            e.printStackTrace();
        }finally {
            jedis.close();
        }
        return -2l;
    }

    public static String get(String key){
        Jedis jedis = new Jedis(HOST);
        try{
            return jedis.get(key);
        }catch(Exception e){
            e.printStackTrace();
        }finally {
            jedis.close();
        }
        return null;
    }
}